package com.uniknow.app.util;

import org.apache.http.HttpResponse;

import android.content.Context;

import com.uniknow.app.AppConfig;
import com.uniknow.app.http.AsyncHttpClient;
import com.uniknow.app.http.AsyncHttpResponseHandler;
import com.uniknow.app.http.FileHttpResponseHandler;
import com.uniknow.app.http.RequestParams;

public class SynchttpClient {
private static SynchttpClient client = null;
	
	private AsyncHttpClient asyncClient = null;
	
	private SynchttpClient(){
		if(asyncClient == null){
			asyncClient = new AsyncHttpClient();
		}
	}
	
	public static SynchttpClient getClient(){
		
		if(client == null){
			client = new  SynchttpClient();
		}		
		return client;
	}
	
	public void post(String url, RequestParams params,
			AsyncHttpResponseHandler responseHandler){
		params.put("fromWhat", "app");//添加请求来源
		if(AppConfig.DeBug){
			Sysout.i("------------------网  络  请  求   开   始-------------------");
			Sysout.i("url = "+url);
			Sysout.i("params = "+params.toString());
			Sysout.i("------------------网  络  请  求  结    束-------------------");
		}
		asyncClient.post(url, params, responseHandler);
	}
	
	public HttpResponse postSyn(String url, RequestParams params){
		return asyncClient.postSyn(url, params);
	}
	
	public void upload(String url, RequestParams params,
			AsyncHttpResponseHandler responseHandler){
		asyncClient.post(url, params, responseHandler);
	}
	
	
	public void download(String url,
			FileHttpResponseHandler fileHttpResponseHandler){
		asyncClient.download(url, fileHttpResponseHandler);
	}
	
	public void cancel(Context context){
		asyncClient.cancelRequests(context, true);
	}
}
